Skip to content

Fix: energy-saving mode stops RTMP stream by implementing it as a pure UI overlay#5

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/investigate-rtmp-stream-issue
Draft

Fix: energy-saving mode stops RTMP stream by implementing it as a pure UI overlay#5
Copilot wants to merge 2 commits intomainfrom
copilot/investigate-rtmp-stream-issue

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 18, 2026

Enabling energy-saving mode (hide preview, dim screen) was stopping the live RTMP stream. The cause: any code path that calls stopPreview() while streaming closes the camera capture session — the encoder loses its frame input and the stream fails. Additionally, startPreview() always constructs a new RtmpCamera2 instance, so re-enabling preview mid-stream would destroy the active streaming object.

Fix

Energy-saving is implemented entirely in the UI layer. The encoder, camera, and RTMP connection are never touched.

  • StreamViewModel — adds isEnergySavingEnabled: StateFlow<Boolean> and toggleEnergySaving(). Resets to false on Idle/Stopped transitions for a clean next session.
  • StreamScreenCameraPreview (SurfaceView) always stays in the Compose composition regardless of energy-saving state. Removing it would trigger surfaceDestroyeddetachPreviewSurface()stopPreview(), breaking the stream. A near-black overlay (0xFF111111) is composited on top when active.
  • Adds a Visibility/VisibilityOff toggle button to the streaming control panel (visible only while streaming), following the existing Mic/MicOff icon-shows-current-state convention.
// StreamScreen — CameraPreview stays in composition at all times
CameraPreview(...)  // always present; encoder unaffected

if (isEnergySavingEnabled) {
    Box(modifier = Modifier.fillMaxSize().background(Color(0xFF111111))) {
        Text("⚡ Energy Saving", ...)
    }
}

Toggling on/off any number of times during a live stream is safe.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/gradle-daemon-main-8.13.jar (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

RTMP stream stops when enabling energy‑saving screen dimming mode on Android
Full Technical Context

Observed problem:
When the newly added energy‑saving feature is enabled (switching off the live preview and turning the screen gray with a minimal UI), the RTMP stream to the RTMP server stops.
Conditions under which it occurs:
This happens specifically when the user activates the energy‑saving mode by pressing the new UI button that disables the live preview during long streaming sessions.
Why this is an issue:
The intended behavior is that the RTMP stream should continue uninterrupted while the preview is disabled, and users should be able to toggle the preview on and off multiple times without breaking the stream. The current behavior breaks the video stream entirely, which defeats the purpose of long‑duration streaming. [Meeting wi...Transcript | Video]

Required Action / Investigation (as explicitly stated)

Investigate and pinpoint where the issue occurs.
Identify why enabling energy‑saving mode stops the RTMP stream.
Make the functionality work so that RTMP streaming continues while the screen is dimmed or preview is disabled. [Meeting wi...Transcript | Video]

Impact if Not Resolved

RTMP video streaming cannot be reliably used for long sessions.
Users cannot use the energy‑saving feature without breaking the stream.
Core streaming functionality is compromised. [Meeting wi...Transcript | Video]

Priority
✅ Explicitly described as critical / major
The issue was referred to as a “major, major issue” and stated to require prompt resolution.

The user has attached the following file paths as relevant context:

  • .github\copilot-instructions.md

Created from VS Code.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ream alive

The energy-saving mode toggle was breaking the RTMP stream because any
implementation that calls stopPreview() on the encoder while streaming
closes the camera capture session — the video encoder loses its frame
input and the stream fails.

Fix: implement energy-saving entirely in the UI layer.
- CameraPreview (SurfaceView) always stays in the Compose composition,
  so surfaceDestroyed / stopPreview is never triggered on the encoder.
- A dark 0xFF111111 overlay composable is shown on top when energy-saving
  is active, hiding the camera feed visually without touching the encoder.
- Toggling on/off any number of times is safe; the RTMP stream is
  completely unaffected.

Changes:
- StreamViewModel: add isEnergySavingEnabled StateFlow, toggleEnergySaving()
  method, and auto-reset to false on stream Idle/Stopped transitions.
- StreamScreen: add energy-saving overlay (Layer 2 in the Box stack),
  add VisibilityOff/Visibility toggle button to the streaming control panel.

Co-authored-by: alxayo <2588978+alxayo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants